package com.tongzhou.tongzhou.quot.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.tongzhou.db.exception.DBException;
import com.tongzhou.tongzhou.quot.dao.IBasePaperDAO;
import com.tongzhou.tongzhou.quot.model.BasePaper;
import com.tongzhou.tongzhou.quot.model.SearchBasePaperCondition;

public class BasePaperAction extends ActionSupport{
	private int id;
	private int paper_paper_id;
	private BasePaper basePaper;
	private List<BasePaper> result=null;
	private SearchBasePaperCondition condition=null;
	
	private int pageSize ;
	private int currentPage ;
	private String orderBy ;
	private String orderByType ;
	private String keng;
	
	private IBasePaperDAO dao=null;
	/**
	 * 原纸列表界面
	 *@author: 彭定雄
	 *@return 
	 *@throws DBException
	 */
	public String listBasePaper() throws DBException{
		checkSearchCondition();
		condition = new SearchBasePaperCondition();
		if (currentPage == 0){
			currentPage = 1;
		}
		condition.setCurrentPage(currentPage) ;
		condition.setOrderBy(orderBy);
		condition.setOrderByType(orderByType) ;
		condition.setPageSize(pageSize) ;
		if(basePaper==null){
			condition.setPaper_paper_id(paper_paper_id);
		}else{
			condition.setPaper_paper_id(basePaper.getPaper_paper_id());
		}
	    result = dao.listBasePaper(condition);
		return "listBasePaper";
	} 
	
	
	/**
	 * 设置列表显示格式
	 *@author: 彭定雄
	 */
	private void checkSearchCondition(){
		if(currentPage <=0){
			currentPage = 1 ;
		}
		
		if(pageSize<=0){
			pageSize = 10 ;
		}
		
		if(orderBy==null||"".equals(orderBy)){
			orderBy = "id" ;
		}
		
		if(orderByType == null || "".equals(orderByType)){
			orderByType = "desc" ;
		}
	}
	
	/**
	 * 新增原纸
	 *@author: 彭定雄
	 *@return
	 *@throws DBException
	 */
	public String toAddBasePaper() throws DBException{
		return "addBasePaper";
	}
	
	public String addBasePaper() throws DBException{
		dao.addBasePaper(basePaper);
		listBasePaper();
		return "listBasePaper";
	}
	
	public String deleteBasePaper() throws DBException{
//		dao=new UserMgrDAO();
		dao.deleteBasePaper(id);
		listBasePaper();
		return "listBasePaper";
	}
	
	public String toEditBasePaper() throws DBException{
		basePaper=dao.getBasePaperById(id);
		return "editBasePaper";
	}
	
	public String editBasePaper() throws DBException{
		dao.updateBasePaper(basePaper);
		listBasePaper();
		return "listBasePaper";
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public int getPaper_paper_id() {
		return paper_paper_id;
	}


	public void setPaper_paper_id(int paperPaperId) {
		paper_paper_id = paperPaperId;
	}


	public BasePaper getBasePaper() {
		return basePaper;
	}


	public void setBasePaper(BasePaper basePaper) {
		this.basePaper = basePaper;
	}


	public List<BasePaper> getResult() {
		return result;
	}


	public void setResult(List<BasePaper> result) {
		this.result = result;
	}


	public SearchBasePaperCondition getCondition() {
		return condition;
	}


	public void setCondition(SearchBasePaperCondition condition) {
		this.condition = condition;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public int getCurrentPage() {
		return currentPage;
	}


	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}


	public String getOrderBy() {
		return orderBy;
	}


	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}


	public String getOrderByType() {
		return orderByType;
	}


	public void setOrderByType(String orderByType) {
		this.orderByType = orderByType;
	}


	public String getKeng() {
		return keng;
	}


	public void setKeng(String keng) {
		this.keng = keng;
	}


	public IBasePaperDAO getDao() {
		return dao;
	}


	public void setDao(IBasePaperDAO dao) {
		this.dao = dao;
	}
}
